//
//  TabbarView.m
//  LINNER
//
//  Created by Kendama on 2017/10/11.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "TabbarView.h"

@implementation TabbarView

#pragma mark -- 点击事件
- (void)didClickBatteryButton
{
    self.batteryButton.selected = YES;
    self.denoiseButton.selected = NO;
    self.balancerButton.selected = NO;
    [self.batteryButton setBackgroundColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]];
    [self.denoiseButton setBackgroundColor:[UIColor whiteColor]];
    [self.balancerButton setBackgroundColor:[UIColor whiteColor]];
    if ([self.delegate respondsToSelector:@selector(tabbarSelected:)])
    {
        [self.delegate tabbarSelected:2];
    }
}

- (void)didClickDenoiseButton
{
    self.denoiseButton.selected = YES;
    self.batteryButton.selected = NO;
    self.balancerButton.selected = NO;
    [self.denoiseButton setBackgroundColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]];
    [self.batteryButton setBackgroundColor:[UIColor whiteColor]];
    [self.balancerButton setBackgroundColor:[UIColor whiteColor]];
    if ([self.delegate respondsToSelector:@selector(tabbarSelected:)])
    {
        [self.delegate tabbarSelected:0];
    }
}

- (void)didClickBalancerButton
{
    self.balancerButton.selected = YES;
    self.denoiseButton.selected = NO;
    self.batteryButton.selected = NO;
    [self.balancerButton setBackgroundColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]];
    [self.denoiseButton setBackgroundColor:[UIColor whiteColor]];
    [self.batteryButton setBackgroundColor:[UIColor whiteColor]];
    if ([self.delegate respondsToSelector:@selector(tabbarSelected:)])
    {
        [self.delegate tabbarSelected:1];
    }
}

- (UIButton *)denoiseButton
{
    if(!_denoiseButton)
    {
        UIView *superView = self;
        _denoiseButton = [[UIButton alloc]init];
        [superView addSubview:_denoiseButton];
        [_denoiseButton setTitle:MyNSLocalizedString(@"降噪模式") forState:UIControlStateNormal];
        [_denoiseButton setImage:[UIImage imageNamed:@"denoise_nor"] forState:UIControlStateNormal];
        [_denoiseButton setImage:[UIImage imageNamed:@"denoise_sel"] forState:UIControlStateSelected];
        [_denoiseButton setTitleColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1] forState:UIControlStateNormal];
        [_denoiseButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_denoiseButton addTarget:self action:@selector(didClickDenoiseButton) forControlEvents:UIControlEventTouchUpInside];
        [_denoiseButton setBackgroundColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]];
        [_denoiseButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:2];

        _denoiseButton.selected = YES;
//        [_denoiseButton.titleLabel setFont:<#(UIFont * _Nullable)#>];
    }
    return _denoiseButton;
}
- (UIButton *)balancerButton
{
    if(!_balancerButton)
    {
        UIView *superView = self;
        _balancerButton = [[UIButton alloc]init];
        [superView addSubview:_balancerButton];
        [_balancerButton setTitle:MyNSLocalizedString(@"均衡器") forState:UIControlStateNormal];
        [_balancerButton setImage:[UIImage imageNamed:@"balancer_nor"] forState:UIControlStateNormal];
        [_balancerButton setImage:[UIImage imageNamed:@"balancer_sel"] forState:UIControlStateSelected];
        [_balancerButton setTitleColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1] forState:UIControlStateNormal];
        [_balancerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_balancerButton addTarget:self action:@selector(didClickBalancerButton) forControlEvents:UIControlEventTouchUpInside];
        [_balancerButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:2];
//        [_balancerButton.titleLabel setFont:<#(UIFont * _Nullable)#>];
    }
    return _balancerButton;
}

- (UIButton *)batteryButton
{
    if(!_batteryButton)
    {
        UIView *superView = self;
        _batteryButton = [[UIButton alloc]init];
        [superView addSubview:_batteryButton];
        [_batteryButton setTitle:MyNSLocalizedString(@"电量") forState:UIControlStateNormal];
        [_batteryButton setImage:[UIImage imageNamed:@"battery_nor"] forState:UIControlStateNormal];
        [_batteryButton setImage:[UIImage imageNamed:@"battery_sel"] forState:UIControlStateSelected];
        [_batteryButton setTitleColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1] forState:UIControlStateNormal];
        [_batteryButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_batteryButton addTarget:self action:@selector(didClickBatteryButton) forControlEvents:UIControlEventTouchUpInside];
        [_batteryButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:2];
//        [_batteryButton.titleLabel setFont:<#(UIFont * _Nullable)#>];
    }
    return _batteryButton;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    UIView *lineView = ({
        lineView = [[UIView alloc]init];
        [superView addSubview:lineView];
        lineView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
        [lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(superView.mas_top);
            make.left.right.mas_equalTo(superView);
            make.height.mas_equalTo(1);
        }];
        lineView;
    });
    
    [self.denoiseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom);
        make.left.mas_equalTo(superView.mas_left);
        make.bottom.mas_equalTo(superView.mas_bottom);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
    }];
    
    [self.balancerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom);
        make.left.mas_equalTo(self.denoiseButton.mas_right);
        make.bottom.mas_equalTo(superView.mas_bottom);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
    }];
    
    [self.batteryButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom);
        make.right.mas_equalTo(superView.mas_right);
        make.bottom.mas_equalTo(superView.mas_bottom);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
    }];
}

@end
